﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:MVVMFramework.View">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/MVVMFramework.View;component/Themes/Common.xaml"/>
        <ResourceDictionary Source="/MVVMFramework.View;component/Themes/Colors.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <!-- =============================================================================== -->
    <!-- ResourceDictionary for TimePicker and related controls                          -->
    <!-- =============================================================================== -->

    <local:BoolInvenrseConverter x:Key="InverseBoolConverter" />
    <local:TimeFormatToDateTimeFormatConverter x:Key="TimeFormatToDateTimeFormatConverter" />

    <LinearGradientBrush x:Key="PopupDarkBorderBrush" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FFA3AEB9" Offset="0" />
        <GradientStop Color="#FF8399A9" Offset="0.375" />
        <GradientStop Color="#FF718597" Offset="0.375" />
        <GradientStop Color="#FF617584" Offset="1" />
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="PopupBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Offset="0" Color="#FFffffff" />
                <GradientStop Offset="1" Color="#FFE8EBED" />
            </GradientStopCollection>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="ListItemHover" Color="#FFE7F5FD" />

    <Style x:Key="TimeItemStyle" TargetType="ListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border Name="Border" Background="{TemplateBinding Background}" SnapsToDevicePixels="true" >
                        <ContentPresenter HorizontalAlignment="Right" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectionBrush}" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectionBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- =============================================================================== -->
    <!-- TimePicker                                                                      -->
    <!-- =============================================================================== -->

    <Style TargetType="{x:Type local:TimePicker}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Background" Value="{x:Static SystemColors.WindowBrush}"/>
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="{StaticResource CommonBorderBrush}"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:TimePicker}">
                    <Grid Name="RootGrid" SnapsToDevicePixels="True">
                        <Border x:Name="Background" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid Grid.IsSharedSizeScope="True">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <local:DateTimeUpDown x:Name="PART_TimeUpDown" 
                                              UpButtonBorderThickness="1,0,0,1" DownButtonBorderThickness="1,1,0,0"
                                              BorderThickness="0"
                                              Background="{TemplateBinding Background}"
                                              Foreground="{TemplateBinding Foreground}"
                                              ContextMenu="{TemplateBinding ContextMenu}"
                                              AllowSpin="{TemplateBinding AllowSpin}"
                                              Format="{TemplateBinding Format, Converter={StaticResource TimeFormatToDateTimeFormatConverter}}"
                                              FormatString="{TemplateBinding FormatString}"
                                              ShowButtonSpinner="{TemplateBinding ShowButtonSpinner}"
                                              Value="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}"
                                              Watermark="{TemplateBinding Watermark}"
                                              WatermarkTemplate="{TemplateBinding WatermarkTemplate}" />

                                <ToggleButton x:Name="_timePickerToggleButton"
                                      Grid.Column="1"
                                      BorderThickness="1,0,0,0"
                                      BorderBrush="Transparent"
                                      Visibility="{Binding ShowDropDown,  RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfTrue}}"
                                      IsChecked="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}}"
                                      Template="{StaticResource DropDownToggleButtonStyle}"
                                      Background="{x:Static SystemColors.WindowBrush}" 
                                      IsHitTestVisible="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolConverter}}" />
                            </Grid>
                        </Border>
                        <Popup IsOpen="{Binding IsChecked, ElementName=_timePickerToggleButton}"
                            StaysOpen="False" Width="{Binding ElementName=RootGrid, Path=ActualWidth}">
                            <Border BorderThickness="1" Background="{StaticResource PopupBackgroundBrush}" BorderBrush="{StaticResource PopupDarkBorderBrush}">
                                <ListBox x:Name="PART_TimeListItems"
                                       BorderThickness="0"
                                       Height="130"
                                       DisplayMemberPath="Display"
                                       ItemContainerStyle="{StaticResource TimeItemStyle}" />
                            </Border>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" TargetName="Background" Value="#FFF7F7F7"/>
                            <Setter Property="Background" TargetName="_timePickerToggleButton" Value="#FFF7F7F7"/>
                            <Setter Property="BorderBrush" TargetName="Background" Value="{StaticResource DisabledBorderBrush}"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" TargetName="_timePickerToggleButton" Value="#FF3399FF"/>
                            <Setter Property="Background" TargetName="_timePickerToggleButton" Value="{StaticResource HoverInnerBackgroundBrush}"/>
                            <Setter Property="BorderBrush" TargetName="Background" Value="#FF3399FF"/>
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter Property="BorderBrush" TargetName="_timePickerToggleButton" Value="#FF3399FF"/>
                            <Setter Property="BorderThickness" TargetName="_timePickerToggleButton" Value="1,0,0,0"/>
                            <Setter Property="Background" TargetName="_timePickerToggleButton" Value="{StaticResource HoverInnerBackgroundBrush}"/>
                            <Setter Property="BorderBrush" TargetName="Background" Value="#FF3399FF"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>